package thread;

/**
 * @author Bboy Dday
 * @create 2020:06:15--10:18
 */
public class BankTest {
}

class Bank{

    private Bank(){}

    private static Bank instance = null;

//    private static synchronized Bank getInstance(){
//        if ( instance == null ){
//            instance = new Bank();
//        }
//        return instance;
//    }

    //方式一：效率稍差
//    private static Bank getInstance() {
//        synchronized (Bank.class) {
//            if (instance == null) {
//                instance = new Bank();
//            }
//            return instance;
//        }
//    }

    //方式二：效率高
    private static Bank getInstance() {
        if (instance == null) {
            synchronized (Bank.class) {
                if (instance == null) {
                    instance = new Bank();
                }
            }
        }

        return instance;
    }

}
